package com.dingwei.lesyndrome.mvp.presenter;

import com.dingwei.lesyndrome.app.MyApplication;
import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.NewsListBean;
import com.dingwei.lesyndrome.bean.SelectedMerchantsBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class PeripheralSearchListPresenter extends basePresenter {

    private Contract.PeripheralSearchListView peripheralSearchListView;

    public PeripheralSearchListPresenter(Contract.PeripheralSearchListView view) {
        super(view);
        this.peripheralSearchListView = view;
    }


    public void initData(String keywords, String orderby, int page, final boolean isRefresh, boolean isShowDiaolg) {
        RequestParams rp = new RequestParams(URLS.HOST+URLS.PERIPHERY_LIST);
        rp.addBodyParameter("longitude", MyApplication.location.getLongitude()+"");
        rp.addBodyParameter("latitude",MyApplication.location.getLatitude()+"");
        rp.addBodyParameter("keywords",keywords);
        rp.addBodyParameter("orderby",orderby);
        rp.addBodyParameter("cpage",page+"");
        x.http().post(rp, new myCallback(BaseActivity.context, SelectedMerchantsBean.class, isShowDiaolg,rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                SelectedMerchantsBean bean = (SelectedMerchantsBean) baseBean;
                if (isRefresh){
                    peripheralSearchListView.onRefresh(bean);
                }else {
                    peripheralSearchListView.onLoadMore(bean);
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                peripheralSearchListView.onFail();
            }
        });
    }
}
